// packageStore/pages/distribution/order/detail.js
import BasePage from '../../../js/common/base-page';
import {api} from '../../../js/util';
import { distribution} from "../../../js/modules/distribution.js";
const app = getApp();
BasePage({

  /**
   * 页面的初始数据
   */
  data: {
    imgDomain: api.imgDomain,
    enableOss: api.enableOss,
    pageIndex:1,
    pageSize:10,
    hasMoreData: true,
    isLoadComplete: false, // 是否已加载数据
    id:0,
    list:[],
    Currency:'',//货币符号
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id) {
      this.setData({
        id: options.id
      })
    }
    this.loadGoodsList()
  },
  loadGoodsList: function () {
    var that = this 
    var pararm = {
      id: this.data.id,
      pageIndex:this.data.pageIndex,
      pageSize:this.data.pageSize
    }
    distribution.loadGoodsList(pararm, function (content) {
      var list = that.data.list;
      if (that.data.pageIndex == 1) {
        list = [];
      }
      if (content.count > 0) {
        var contentlist = content.data;
        if (contentlist.length < that.data.pageSize) {
          that.setData({
            list: list.concat(contentlist),
            hasMoreData: false,
            isLoadComplete: true,
          });
        } else {
          that.setData({
            list: list.concat(contentlist),
            hasMoreData: true,
            pageIndex: that.data.pageIndex + 1,
            isLoadComplete: true,
          });
        }
  
      } else {
        that.setData({
          list: [],
          hasMoreData: true,
          pageIndex: 1,
          isLoadComplete: true,
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      Currency:api.Currency || '￥'
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    this.setData({
      pageIndex: 1,
      isLoadComplete: false,
    })
    this.loadGoodsList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function (e) {
    if (this.data.hasMoreData) { 
      this.loadGoodsList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})